import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import * as path from "path";

import { getScssVars } from "./src/styles/variables";

const isBuild = process.env.NODE_ENV === 'production';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(), 
    Components({
      resolvers: [NaiveUiResolver()]
    })
  ],
  esbuild: {
    drop: isBuild ? ['console', 'debugger'] : undefined
  },
  build: {
    cssCodeSplit: false,
    rollupOptions: {
      output: {
        manualChunks: {
          'icons': ['/src/components/Icon/index.ts']
        }
      }
    }
  },
  resolve: {
    alias: {
      "@": path.join(__dirname, "./src"),
      "@styles": path.join(__dirname, "./src/styles"),
      "@layout": path.join(__dirname, "./src/layout"),
      "@components": path.join(__dirname, "./src/components"),
      "@utils": path.join(__dirname, "./src/utils"),
      "@stores": path.join(__dirname, "./src/stores"),
      "@views": path.join(__dirname, "./src/views"),
      "@router": path.join(__dirname, "./src/router"),
      "#package": path.join(__dirname, "./package.json"),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: getScssVars() + '@import "@styles/index.scss";'
      },
    }
  },
  server: {
    proxy: {
      '/nopig-api': {
        target: 'http://123.60.188.72:8080',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/nopig-api/, ''),
      },
    }
  }
});
